// 初始化 开始时间YYYY-MM-DD 00:00:00/结束时间YYYY-MM-DD 23:59:59
export const initTime = (date, direction) => {
	var Y = date.getFullYear() + '-';
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());

	return direction === 'start' ? `${Y}${M}${D} 00:00:00` : `${Y}${M}${D} 23:59:59`
}

// 日
export const getDayStartEnd = () => {
	let date = new Date()
	const start = initTime(date, 'start')
	const end = initTime(date, 'end')
	console.log(start, end)
	return {
		startDate: start,
		endDate: end
	}
}

// 周
export const getWeekStartEnd = () => {
	const dayjs = require('dayjs')
	const weekday = dayjs().day()
	const we = weekday === 0 ? 0 - 1 : 0
	const beginDate = dayjs().add(we, 'week').startOf('week').add(1, 'day').valueOf()
	const endDate = dayjs().add(we, 'week').endOf('week').add(1, 'day').valueOf()

	//初始化日期时间
	let monday = initTime(new Date(beginDate), 'start')
	let sunday = initTime(new Date(endDate), 'end')
	console.log(monday, sunday)
	return {
		startDate: monday,
		endDate: sunday,
	}
}

// 年
export const getMonthStartEnd = () => {
	let currentDate = new Date();
	// 获取当前月份的第一天
	let firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
	// 获取当前月份的最后一天
	let lastDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
	const firstDay = initTime(firstDayOfMonth, 'start')
	const lastDay = initTime(lastDayOfMonth, 'end')
	console.log(firstDay, lastDay)
	return {
		startDate: firstDay,
		endDate: lastDay,
	}
}

//根据范围类型range获取当前的值
export const initStarAndEndDate = (range) => {
	if (range === 'day') {
		return getDayStartEnd()
	} else if (range === 'week') {
		return getWeekStartEnd()
	} else if (range === 'month') {
		return getMonthStartEnd()
	}
}